#include "threadPool.h"
int func_puts(int netfd,char * true_name,char * filename,stringStack_t * stack) {
    train_t *pTrain =(train_t *) calloc(1, sizeof(train_t));
    int ret = access(true_name, F_OK);
    if (ret == -1) {
        printf("文件不存在!\n");
        return -1;

    }
    int fd = open(true_name, O_RDWR);
    if (fd == -1) {
        printf("open file is failed!\n");
        return -1;

    }

    struct stat statbuf;
    fstat(fd, &statbuf);
    off_t filesize = statbuf.st_size;
    printf("filesize = %ld\n", filesize);

    pTrain->length =strlen(filename);
    memcpy(pTrain->data, filename, strlen(filename));
    send(netfd, &pTrain->length, sizeof(pTrain->length), MSG_NOSIGNAL);
    send(netfd, pTrain->data, pTrain->length, MSG_NOSIGNAL);

    send(netfd, &filesize,sizeof(off_t), MSG_NOSIGNAL);

    while(1) {
        bzero(pTrain->data, sizeof(pTrain->data));
        ssize_t sret =read(fd, pTrain->data, sizeof(pTrain->data));
        if(sret == 0) break;
        pTrain->length = sret;
        send(netfd, &pTrain->length, sizeof(pTrain->length), MSG_NOSIGNAL);
        send(netfd, pTrain->data, pTrain->length, MSG_NOSIGNAL);
    }
    close(fd);
    return 0;
}
